{include file="public/toper"/}
<style>
    .layui-unselect{width: 190px;}
    .layui-table {width: 70%;margin-left: 2%;}
    .layui-table  th ,.layui-table td { border: 0;}
    .layui-table td {padding-left: 70px;}
    .color{color: #FF0000;}
</style>
<div class="x-body"><form action="" method="post" class="layui-form" id="forms">
    <table class="layui-table">
        <th class="">商品信息</th>
        <tr><td>订单编号:{$order.order_sn}</td><td>订单状态:<span class="color">
             {if condition = "$order.order_status  eq 0 "}未付款
            {elseif condition = "$order.order_status  eq 1 "/}已付款
            {elseif condition = "$order.order_status  eq 2 "/}已发货
            {elseif condition = "$order.order_status  eq 3 "/}已完成
            {elseif condition = "$order.order_status  eq 4 "/}已取消
            {elseif condition = "$order.order_status  eq 5 "/}归还中
            {elseif condition = "$order.order_status  eq 6 "/}店铺已收货
            {elseif condition = "$order.order_status  eq 7 "/}已验收
            {elseif condition = "$order.order_status  eq 8 "/}待用户确认
            {elseif condition = "$order.order_status  eq 9 "/}待用户支付
            {elseif condition = "$order.order_status eq 10 "/}租赁中
            {/if}
        【{$order.uname},<span id="sj">{$order.uphone}</span>】</span></td></tr>
        <tr>
            <td>商品信息：
                {volist name="$order['goods']" id="vo"}
                <p>{$vo.sname}    &nbsp;&nbsp;&nbsp;{if condition = "$vo.spec_item_key  neq '0'"}{$vo.spec_item_key}{/if}  &nbsp;&nbsp;&nbsp; *{$vo.goods_number}</p>
                {/volist}
            </td>
        </tr>

        <th class="">共享信息</th>;
                <tr><td>共享期：<?php echo floor(((strtotime(date('Y-m-d',$order['lease_end_time']))+86400)-strtotime(date('Y-m-d',$order['lease_time'])))/86400);?>天 &nbsp;&nbsp;&nbsp;【{$order['lease_time']|date="Y-m-d",###}到
                    {$order['lease_end_time']|date="Y-m-d",###} 】</td></tr>
                <tr> <td>实际归还日期：{$order['lease_end_time']|date="Y-m-d",###}&nbsp;&nbsp;&nbsp;<span style="color: #CC0000;">【逾期天数{$order.overdue_number}天】</span></td></tr>
        {if condition = "$order.overdue_number  neq 0"}
        <th class="">逾期处理</th>
                <tr><td>日租：<span id="rz">{$order.sum_price}</span></td></tr>
                <tr><td>逾期天数：<span id="yqts">{$order.overdue_number}</span></td></tr>
                <tr><td>减免天数： <input type="number" min="1" value="{$order.reduction_number}" id="jianmian" name="reduction_number" autocomplete="off" class="layui-input" style="width: 190px;"></td></tr>
                <tr><td>逾期总费用：<span class="color">￥</span><span class="color" id="yqfy">{$order.overdue_price}</span></td></tr>
                        <input type="hidden" value="{$order.overdue_price}" id="zs">
        {/if}


    </table>

    <th class="">磨损处理</th>
            <input type="radio" name="discount" value="1" lay-filter="filter" {if condition = "$order.abrasion_price neq 0"}  checked="checked"{/if} title="有磨损">
            <input type="radio" name="discount" value="0" lay-filter="filter" {if condition = "$order.abrasion_price eq 0"}  checked="checked"{/if} title="没有">

    <div class="layui-form-item a" style="display: none">
        <label class="layui-form-label">
            <span class="x-red">*</span>说明
        </label>
        <div class="layui-input-inline">
            <textarea type="number" value="" min="1" name="abrasion_explain" autocomplete="off" class="layui-input">{$order.abrasion_explain}</textarea>
        </div>
    </div>

    <div class="layui-form-item a" style="display: none">
            <label class="layui-form-label">
                <span class="x-red">*</span>图片
            </label>
            <div class="layui-input-inline layui-upload" id="upload-thumb" style="width: 80%">
                <button type="button" class="layui-btn layui-btn-primary" id="image"><i class="layui-icon"></i>上传图片</button>
                {if condition = "$order.abrasion_price >0 "}
                <div class="layui-upload-list images-block-container" id="demo">
                    {if condition = "$order.abrasion_img[0] neq '0'"}
                    {volist name="$order.abrasion_img" id="vo"}
                    <span class="image-block"><input name="abrasion_img[]" value="{$vo}" type="hidden">
                      <span class="del_btn"><i class="layui-icon">&#x1006;<img src="{$vo}" class="layui-upload-img" width="100" height="100"></i></span></span>
                    {/volist}
                    {/if}
                </div>
                {else /}
                <div class="layui-upload-list images-block-container" id="demo"></div>
                <p id="demoText"></p>
                {/if}
            </div>
    </div>
    <div class="layui-form-item a" style="display: none">
        <label for="abrasion_price" class="layui-form-label">
            <span class="x-red"></span>磨损费用
        </label>
        <div class="layui-input-inline">
            <input type="number" value="{$order.abrasion_price}" id="abrasion_price" name="abrasion_price" class="layui-input">
        </div>
    </div>


    <table class="layui-table">
        <th class="">合计</th>
        <tr><td>合计费用：<span class="color"> ￥</span><span id="hjfy" class="color"> {$order.overdue_price}</span></td></tr>
        <tr><td>用户已现付押金： ￥<span id="yaj">{$order.deposit_price}</span></td></tr>
        <tr class="z" style="display: none">
            <td>仍需支付： <span class="color">￥</span><span id="r" class="color"></span></td>
            <input type="hidden" name="business_payment_pay" value="" />
        </tr>
        <tr class="t" style="display: none">
            <td>需要退款： <span class="color">￥</span><span id="tuikuan" class="color"></span></td>
            <input type="hidden" name="refund_price" value="" />
        </tr>
    </table>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <input type="hidden" name="order_id" value="{$order.order_id}" />
            <button  class="layui-btn" lay-filter="formSubmit" lay-submit="">提交</button>
        </div>
    </form>
</div>

<script>

    var phone = $('#sj').text();
    var nPhone = phone.substr(0, 3) + '****' + phone.substring(7, 11);
    $('#sj').text(nPhone);

    $("#sj").click(function(){
        var p = $('#sj').text();
        if(p.indexOf("***") >= 0 ) {
            $('#sj').text({$order['uphone']});
        }else {
            var nP = p.substr(0, 3) + '****' + p.substring(7, 11);
            $('#sj').text(nP);
        }
    });


    layui.use(['form','layer','upload'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer,
            upload = layui.upload;


        form.render('radio');

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#image',
            url: "{:url('admin/Upload/abrasion')}",
            ext: 'jpg|png|gif',
            multiple:true,
            number:8,
            drag:false,
            before: function(obj){
                //预读本地文件示例，不支持ie8
                // obj.preview(function(index, file, result){
                //     $('#demo').attr('src', result); //图片链接（base64）
                // });
            },
            done: function(res){
                //如果上传失败
                if(res.code == 200 ){
                    $('#demo').append('<span class="image-block"><input type="hidden" name="abrasion_img[]" value="'+ res.data.src +'"><span class="del_btn"><i class="layui-icon">&#x1006;<img width="100" height="100" src="'+ res.data.src +'" class="layui-upload-img"></i></span></span>');
                }else {
                    layer.msg(res.msg);
                }
                //上传成功
            },
            error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });

        var mo = {$order.abrasion_price};
        if(mo>0){
            $(".a").css("display","block");
        }


        form.on('radio(filter)', function(data){
            if(data.value==1){
               $(".a").css("display","block");
                $("#abrasion_price").val(0);
            }else {
                $(".a").css("display","none");

                var y = Number($("#yqts").text());

                var yaj = $("#yaj").text();

                var yqfy = Number($("#yqfy").text());
                yqfy = yqfy.toFixed(2);

                $("#hjfy").text(yqfy);


                $("#r").text(yqfy-yaj);
                $('input[name="business_payment_pay"]').val(yqfy-yaj);

                if(yqfy<yaj){
                    $("#tuikuan").text((yaj-yqfy));
                    $('input[name="refund_price"]').val((yaj-yqfy));
                }

                if(yqfy<yaj){
                    $('input[name="business_payment_pay"]').hide();
                    $(".z").hide();
                    $("#r").hide();
                    $("#r").text(0);
                    $('input[name="business_payment_pay"]').val(0);

                    $("#tuikuan").text((yaj-yqfy));
                    $("#tuikuan").show();
                    $('input[name="refund_price"]').val((yaj-yqfy));
                    $(".t").css("display","block");



                }else {
                    $("#tuikuan").hide();
                    $('input[name="refund_price"]').hide();
                    $(".t").hide();

                    $("#r").text(yqfy-yaji);
                    $('input[name="business_payment_pay"]').val(yqfy-yaji);
                    $(".z").css("display","block");

                }
                // console.log(y);
                // console.log(yaj);
                // console.log(yqfy);
            }
        });

        $('.images-block-container').on('click','.del_btn',function(){
            var index_image = $(this).parents('.image-block').remove();
        });


        $("body").on("keyup","input[name=\"reduction_number\"]",function(){
            var jm = Number($(this).val());
            var y = Number($("#yqts").text());

            var yaj = $("#yaj").text();
            if(jm<0){
                layer.msg('输入值错误，不能为负数',{time:1000,icon:2});
                $(this).val(0);
                return false;
            }
            if(jm>y){
                layer.msg('输入值错误，天数超过逾期天数',{time:1000,icon:2});
                return false;
            }
            //var yqfy = Number($("#yqfy").text());
            var yqfy = Number($("#zs").val());

            var yqts = Number($("#yqts").text());
            if(jm!=''){
                var rz = Number($("#rz").text());
                var abrasion_price = Number($("#abrasion_price").val());

                var discount = Number($("input[name=\"discount\"]:checked").val());

                if(yqfy<yaj){
                    if(discount==0){
                        var ru = (yqts*rz)-(rz*jm);
                        ru = ru.toFixed(2);
                        $("#yqfy").text(ru);

                        $("#hjfy").text(ru);
                        var rest = Math.abs(ru-yaj);
                        $("#tuikuan").text(rest);
                        $('input[name="refund_price"]').text(rest);
                        $('input[name="refund_price"]').val(rest);
                    }else {
                        var yuqizong = yqfy-(jm*rz);
                        yuqizong = yuqizong.toFixed(2);
                        $("#yqfy").text(yuqizong);
                        $("#hjfy").text(yuqizong+abrasion_price);

                        $("#tuikuan").text((yaj-yuqizong-abrasion_price));
                        $('input[name="refund_price"]').val((yaj-yuqizong-abrasion_price));
                    }
                }else {
                    if(discount==0){
                        var zhi = (yqfy-(rz*jm));
                        zhi = zhi.toFixed(2);
                        $("#yqfy").text(zhi);
                        $("#hjfy").text(zhi);
                        if(zhi<yaj){
                            $('input[name="business_payment_pay"]').hide();
                            $(".z").hide();
                            $("#r").hide();
                            $("#r").text(0);
                            $('input[name="business_payment_pay"]').val(0);


                            $("#tuikuan").text((yaj-zhi));
                            $("#tuikuan").show();
                            $('input[name="refund_price"]').val((yaj-zhi));
                            $(".t").css("display","block");

                        }else {

                            $('input[name="refund_price"]').hide();
                            $(".t").hide();
                            $("#tuikuan").hide();
                            $("#tuikuan").text(0);
                            $('input[name="refund_price"]').val(0);



                            var renxu = (yqfy-(rz*jm)-yaj);
                            renxu = renxu.toFixed(2);

                            $("#r").text(renxu);
                            $("#r").show();
                            $('input[name="business_payment_pay"]').val(renxu);
                            $(".z").css("display","block");
                        }
                    }else {
                        var prces = yqfy-(jm*rz);
                        $("#yqfy").text(prces);

                        var prce =prces+abrasion_price;


                        $("#hjfy").text(prce);
                        $("#r").text(prce-yaj);
                        $('input[name="business_payment_pay"]').val(prce-yaj);
                    }
                }
            }else {
                $('input[name="refund_price"]').hide();
                $(".t").hide();
                $("#tuikuan").hide();
                $("#tuikuan").text(0);
                $('input[name="refund_price"]').val(0);


                $("#yqfy").text($("#zs").val());
                $("#hjfy").text($("#zs").val());
                $("#r").text($("#zs").val()-yaj);
                $('input[name="business_payment_pay"]').val($("#zs").val()-yaj);
                $(".z").css("display","block");
                if(yqfy<yaj){
                    $("#tuikuan").text((yaj-$("#zs").val()));
                    $('input[name="refund_price"]').val((yaj-$("#zs").val()));
                }
            }

        });


        $("body").on("keyup","input[name=\"abrasion_price\"]",function(){
            var abrasion_price = Number($(this).val());

            var yaj = Number($("#yaj").text());
            var yqfy = $("#yqfy").text();

            var hjfy= $("#hjfy").text();

            var rz = $("#rz").text();
            //console.log((abrasion_price));
            //console.log($.type(abrasion_price));
             //console.log((yqfy));
            if(abrasion_price!=''){
                //console.log($.type(yqfy));
                var prce = abrasion_price+Number(yqfy);
                prce = prce.toFixed(2);
                //console.log((prce));
                $("#hjfy").text(prce);
                var payment = (prce-yaj);
                payment = payment.toFixed(2);
                $("#r").text(payment);
                $('input[name="business_payment_pay"]').val(payment);

                //console.log($.type(prce));
                //console.log(($.type(yaj)));
                if(prce<=yaj){

                    $('input[name="business_payment_pay"]').hide();
                    $(".z").hide();
                    $("#r").hide();
                    $("#r").text(0);
                    $('input[name="business_payment_pay"]').val(0);

                    var refund = (yaj-prce);
                    payment = refund.toFixed(2);

                    $("#tuikuan").text(payment);
                    $("#tuikuan").show();
                    $('input[name="refund_price"]').val(payment);
                    $(".t").css("display","block");



                }else {
                    $("#tuikuan").hide();
                    $('input[name="refund_price"]').hide();
                    $(".t").hide();

                    $("#tuikuan").text(0);
                    $('input[name="refund_price"]').val(0);

                    var business = (prce-yaji);
                    business = business.toFixed(2);

                    $("#r").text(business);
                    $("#r").show();
                    $('input[name="business_payment_pay"]').val(business);
                    $(".z").css("display","block");

                }


            }else {

                $("#hjfy").text($("#yqfy").text());
                $("#r").text($("#yqfy").text()-yaj);
                $('input[name="business_payment_pay"]').val($("#yqfy").text()-yaj);

                if(hjfy<yaj){
                    $("#tuikuan").text((yaj-$("#yqfy").text()));
                    $('input[name="refund_price"]').val((yaj-$("#yqfy").text()).toFixed(2));
                }else {
                    $("#tuikuan").hide();
                    $('input[name="refund_price"]').hide();
                    $(".t").hide();

                    var payment_pay = (hjfy-yaji);
                    payment_pay = payment_pay.toFixed(2);

                    $("#r").text(payment_pay);
                    $('input[name="business_payment_pay"]').val(payment_pay);
                    $(".z").css("display","block");

                }


            }

        });



        var heji = Number({$order.overdue_price});
        var yaji = Number({$order.deposit_price});

        var sum_price = Number({$order.sum_price});
        var day = Number($('#jianmian').val());
        //console.log($.type(day));

        if(isNaN(day) ||day==''){
            day = 0;
        }

        var sum = sum_price*day;

        var yqfy = $("#yqfy").text();
        if(yqfy==''){
            yqfy = 0;
        }

        if(sum==''){
            sum = 0;
        }

        var yqzfy = yqfy-sum;
        yqzfy = Number(yqzfy.toFixed(2));
        $("#yqfy").text(yqzfy);

        var abrasion_price = Number($('#abrasion_price').val());
        // console.log($.type(abrasion_price));
        // console.log($.type(yqzfy));
        $('#hjfy').text(yqzfy+abrasion_price);

        //console.log($.type(yqzfy+abrasion_price));
        heji = yqzfy+abrasion_price;
        if(heji>yaji){
            $("#r").text(heji-yaji);
            $('input[name="business_payment_pay"]').val(heji-yaji);
            $(".z").css("display","block");
        }else {
            $("#tuikuan").text(yaji-heji);
            $('input[name="refund_price"]').val(yaji-heji);
            $(".t").css("display","block");
        }

    });
</script>
{include file="public/footer"/}